package cn.com.wms.controller;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import cn.com.wms.Base.FilterInfo;
import cn.com.wms.Base.QueryResult;
import cn.com.wms.model.MaterialInfoBean;
import cn.com.wms.service.MaterialInfoService;

import org.apache.commons.lang.StringUtils;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * controller
 */
@Controller
@RequestMapping("/materialInfo")
public class MaterialInfoController extends BaseController {

    private static Logger _log = LoggerFactory.getLogger(MaterialInfoController.class);

    @Autowired
    private MaterialInfoService materialInfoService;

    @RequestMapping(value = "/index")
    public ModelAndView index() {
    	 ModelAndView modelAndView = new ModelAndView();  
    	  
    	    modelAndView.setViewName("index");  
        return modelAndView;
    }
   /* @RequestMapping(value = "/index")
    public String index() {  
       return "/materialInfo/index";
   }*/

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ResponseBody
    public Object list(
            @RequestParam(required = false, defaultValue = "0", value = "indexPage") int indexPage,
            @RequestParam(required = false, defaultValue = "10", value = "limit") int limit,
            @RequestParam(required = false, defaultValue = "", value = "search") String search,
            @RequestParam(required = false, value = "sort") String sort,
            @RequestParam(required = false, value = "order") String order) {
    	MaterialInfoBean materialInfo = new MaterialInfoBean();
    	pageBean.setIndexPage(indexPage);
    	Map<String, Object> queryMap = new HashMap<String, Object>();
//		EmployBean employ=(EmployBean)getSession().getAttribute("userInfo");
		FilterInfo filters = this.getFilterInfo(this.queryMap);
		materialInfoService.verifyByName("1");
//		filters.addFilterItem(new FilterItem("a","companyType",employ.getCompanyType(),LogicOperate.EQUAL));
//		filters.addFilterItem(new FilterItem("a","reportTypeOne",objectModel,LogicOperate.EQUAL));
		QueryResult queryResult = materialInfoService.queryResultMaterialInfoList(filters, pageBean);
		pageBean.setAllRows(queryResult.getTotalRecordNumber());
		List<MaterialInfoBean> materialInfoBeanList=queryResult.getResultList();
		List<MaterialInfoBean> materialInfoBeanListx=materialInfoService.queryMaterialInfoList();
//        long total = upmsLogService.countByExample(upmsLogExample);
        Map<String, Object> result = new HashMap<String, Object>();

        result.put("rows", materialInfoBeanListx);
//        result.put("rows", materialInfoBeanList);
//        result.put("pageBean", pageBean);
        return result;
    }

}